IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace > EntityManager Class > InvokeServerMethodAsync Method : InvokeServerMethodAsync(ServerMethodDelegate,CancellationToken,Object[]) Method |
static
(Shared
in Visual Basic) method for execution on the server.'Declaration
Public Overloads Function InvokeServerMethodAsync( _ ByVal serverMethod As ServerMethodDelegate, _ ByVal cancellationToken As CancellationToken, _ ByVal ParamArray userArguments() As Object _ ) As Task(Of Object)
'Usage
Dim instance As EntityManager Dim serverMethod As ServerMethodDelegate Dim cancellationToken As CancellationToken Dim userArguments() As Object Dim value As Task(Of Object) value = instance.InvokeServerMethodAsync(serverMethod, cancellationToken, userArguments)
public Task<object> InvokeServerMethodAsync( ServerMethodDelegate serverMethod, CancellationToken cancellationToken, params object[] userArguments )
Exception | Description |
---|---|
System.InvalidOperationException | Invalid ServerMethodDelegate provided |
System.ArgumentException | UserState token must be unique for the client |
System.Security.SecurityException | Thrown if the method is not marked with the AllowRpcAttribute |
PersistenceSecurityException | Thrown if the server method is decorated with a AuthorizationAttribute and fails authorization |
InvokeServerMethodAsync enables a client-side caller to invoke an arbitrary static method on the server using an asynchronous call. An outstanding request can be canceled using the System.Threading.CancellationToken.
This feature is only available in certain editions of DevForce.// Sample showing asynchronous invocation of server method // In client class: private void MakeAsyncCall() { EntityManager mgr = new DomainModelEntityManager(); // Make async call Guid myToken = Guid.NewGuid(); mgr.InvokeServerMethodAsync(new ServerMethodDelegate(Order.GetNumberOfOrdersSlow), InvokeServerMethodAsyncCompleted, myToken, new DateTime(1995, 1, 1), new DateTime(1999, 1, 1)); } private void InvokeServerMethodAsyncCompleted(InvokeServerMethodOperation e) { Guid token = (Guid)e.UserState; if (!e.Cancelled) { MessageBox.Show("my async result = " + Convert.ToInt32(e.Result).ToString()); } } // Sample method defined in Order entity class: public class Order { //... // ServerMethodDelegate method, called from client [AllowRpc] public static Object GetNumberOfOrdersSlow(IPrincipal pPrincipal, EntityManager pMgr, params Object[] pArgs) { // Sleep to make this slower to show async System.Threading.Thread.Sleep(2000); DateTime dt1 = pArgs[0] as DateTime; DateTime dt2 = pArgs[1] as DateTime; return pMgr.Order.Where(o => o.OrderDate >= dt1 && o.OrderDate <= dt2).Count(); } }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2